<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>超级群管理员列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/my.css/}" media="all">

</head>
<body class="body">
<input name="ultragroupId" th:value="${ultragroupId}" type="hidden" />
<script type="text/html" id="topOperate">
    <div class="my-btn-box layui-form">
      <span class="fl">
    <button class="layui-btn layui-btn-sm" lay-event="toSave"><i class="layui-icon layui-icon-add-1"></i>添加</button>
      </span>
    </div>
</script>
<div class="layui-card">
    <div class="my-btn-box layui-form">
            <span class="fr">
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="userId" placeholder="管理员用户ID" class="layui-input height33">
                </div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="nick" placeholder="管理员用户昵称" class="layui-input height33">
                </div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="mobile" placeholder="管理员手机号" class="layui-input height33">
                </div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="realName" placeholder="管理员真实姓名" class="layui-input height33">
                </div>
                <button class="layui-btn layui-btn-sm" id="search"><i class="layui-icon">&#xe615;</i>搜索</button>
            </span>
    </div>
</div>
<!-- 表格 -->
<div id="dateTable" lay-filter="event"></div>
<div class="height50"></div>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/fyn/index.js}"></script>
<script th:src="@{/js/fyn/my.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_table.js}"></script>
<script type="text/javascript" th:inline="javascript">

    // layui方法
    layui.use(['table', 'form', 'laypage', 'layer', 'vip_table','laydate'], function () {
        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , $ = layui.jquery;

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            // , skin: 'line'
            , even: 'true'
            , cols: [[                  //标题栏
                 {
                    field: 'ultragroupId', title: '超级群ID',minWidth: 100, align: 'center'
                }
                , {
                    field: 'ultragroupName', title: '超级群名称', minWidth: 100, align: 'center'
                }
                , {
                    field: 'userId', title: '管理员用户ID', minWidth: 100, align: 'center'
                }
                , {
                    field: 'nick', title: '管理员用户昵称', minWidth: 100, align: 'center'
                }
                , {
                    field: 'mobile', title: '管理员手机号', minWidth: 100, align: 'center'
                }
                , {
                    field: 'realName', title: '管理员真实姓名', minWidth: 100, align: 'center'
                }
                , {title: '操作', align: 'center',minWidth: 250, toolbar: '#barOption'} //这里的toolbar值是模板元素的选择器
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/ultragroup/ultragroupAdminList'
            , method: 'get'
            , page: true
            , limits: [10, 30, 60, 90, 150, 300]
            , toolbar: '#topOperate'
            , limit: 10 //默认采用0
            , loading: true
            // , where: getJson()
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                $("td[data-field='content']").each(function () {
                    $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                });

            }
        });



        //头工具栏事件
        table.on('toolbar(event)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'toSave':
                    layer.prompt({
                        formType: 0,
                        value: '',
                        title: '请输入管理员明文ID',
                        area: ['800px', '350px'] //自定义文本域宽高
                    }, function (value, index, elem) {
                        if (value == null || value == '') {
                            layer.msg("管理员明文ID不能为空", {icon: 6, time: 1500});
                            return;
                        }
                        var loadingIndex = layer.load(1, {
                            shade: [0.1,'#fff'] //0.1透明度的白色背景
                        });

                        $.ajax({
                            type: "post",
                            url: [[${basePath}]] + "/ultragroup/createUltragroupAdmin",
                            data: {
                                ultragroupId: $("input[name='ultragroupId']").val(),
                                userIds: value
                            },
                            success: function (res) {
                                if (res.success) {
                                    layer.msg("创建成功！", {icon: 1}, 2000);
                                    layer.close(index);
                                    tableIns.reload();
                                } else {
                                    layer.msg(res.msg, {icon: 2}, 2000);
                                }
                                layer.closeAll("loading");
                            }
                        });

                        layer.close(index);
                    });
                    break;
            }
        });
        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm("确定删除该超级群管理员?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/ultragroup/deleteUltragroupAdmin",
                        data: {
                            ultragroupId: data.ultragroupId,
                            userId: data.userId
                        },
                        success: function (res) {
                            if (res.success) {
                                layer.msg("操作完成", {icon: 1}, 500);
                                layer.close(index);
                                tableIns.reload();
                            }
                        }
                    });
                });
            }

        });

        function getJson() {
            return {
                where: {
                    ultragroupId: $("input[name='ultragroupId']").val(),
                    userId: $("input[name='userId']").val(),
                    nick: $("input[name='nick']").val(),
                    mobile: $("input[name='mobile']").val(),
                    realName: $("input[name='realName']").val(),
                }
            };
        }
        $("#search").click(function () {
            tableIns.reload({
                where: {
                    ultragroupId: $("input[name='ultragroupId']").val(),
                    userId: $("input[name='userId']").val(),
                    nick: $("input[name='nick']").val(),
                    mobile: $("input[name='mobile']").val(),
                    realName: $("input[name='realName']").val(),
                },
                page: {
                    curr: 1
                }
            });
        })
        setTimeout(function(){
            tableIns.reload(getJson());
        }, 100);
    });
</script>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barOption">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-add"></i>删除</a>
</script>
</body>
</html>